package com.wbcs.jbsf.auth.interceptor;

import java.sql.SQLException;

import com.wbcs.config.component.application.report.ReportBean;
import com.wbcs.jbsf.auth.abs.AbstandLogin;
import com.wbcs.jbsf.auth.abs.impl.WbcsLogin;
import com.wbcs.jbsf.util.JBSFConsts;
import com.wbcs.jbsf.util.Wbcs4JBSFUtil;
import com.wbcs.system.ReportRequest;
import com.wbcs.system.inputbox.SelectBox;
import com.wbcs.system.intercept.AbsInterceptorDefaultAdapter;

public class ItprLogin extends AbsInterceptorDefaultAdapter
{
    @Override
	public void doStart(ReportRequest rrequest,ReportBean rbean)
    {
        String srpath = rrequest.getStringAttribute("srpath");
        if(srpath != null && (JBSFConsts.JBSF_ROUTE_MARK_INDEX).equals(srpath)){//注销
            System.out.println("session invalidate...................................................");
            rrequest.getRequest().getSession().invalidate();
        }
        String username=rrequest.getStringAttribute("txtusername","");//取出输入的“工号”条件值
		String password=rrequest.getStringAttribute("txtpassword","");//取出输入的“姓名”条件值
		if("".equals(username)&&"".equals(password)){
			rrequest.setAttribute("loginRpt_lazyload","true");
		}
    }
    
    /* 
     * 进行登录判断及用户信息存储
     */
    @Override
	public Object afterLoadData(ReportRequest rrequest,ReportBean rbean,Object typeObj,Object dataObj)
    {
        if(typeObj instanceof SelectBox)
            return dataObj;
        if(dataObj == null && rrequest.getAttribute("WX_ISAJAXLOAD") != null ){
            rrequest.getWResponse().getMessageCollector().error("用户名或密码错误！","", false);
            return dataObj;
        }
        if(dataObj == null)return dataObj;
        //登录判断
        String msg = "";
		try {
			msg = new WbcsLogin(rrequest.getRequest(), rrequest.getWResponse().getResponse())
			             .initParams(rrequest,rbean,typeObj,dataObj).addRequestStatus(AbstandLogin.RequestStatus.wbcs).doLogin();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        //用户名或密码错误
        if(!Wbcs4JBSFUtil.isOk(msg))rrequest.getWResponse().getMessageCollector().error(msg,"", false);
        
        return dataObj;
    }
}

